package com.bamboowind.rabbitmq.direct.config;

import org.springframework.amqp.core.Binding;
import org.springframework.amqp.core.BindingBuilder;
import org.springframework.amqp.core.DirectExchange;
import org.springframework.amqp.core.Queue;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * RabbitMQ的direct模式的配置类
 *
 * @author Blue
 */
@Configuration
public class RabbitConfigDirect {

    /**
     * 创建队列direct_queue
     *
     * @return
     */
    @Bean
    public Queue directQueue() {
        return new Queue("direct_queue");
    }

    /**
     * 创建队列direct_queue2
     *
     * @return
     */
    @Bean
    public Queue directQueue2() {
        return new Queue("direct_queue2");
    }

    /**
     * 创建direct模式下的交换机direct_exchange
     *
     * @return
     */
    @Bean
    public DirectExchange directExchange() {
        return new DirectExchange("direct_exchange");
    }

    /**
     * 将队列direct_queue与交换机direct_exchange绑定,routingKey为direct
     *
     * @return
     */
    @Bean
    public Binding bindingDirectQueue() {
        return BindingBuilder.bind(directQueue()).to(directExchange()).with("direct");
    }

    /**
     * 将队列direct_queue2与交换机direct_exchange绑定,routingKey为direct2
     *
     * @return
     */
    @Bean
    public Binding bindingDirectQueue2() {
        return BindingBuilder.bind(directQueue2()).to(directExchange()).with("direct2");
    }
}
